package nus.edu.sg.db;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import nus.edu.sg.config.Config;

import org.omg.CORBA.portable.InputStream;

import oracle.jdbc.pool.OracleDataSource;

public class DBConnection 
{
    String jdbcUrl = null;
    String userid = null;
    String password = null; 
    OracleDataSource datasource= null;
    private static DBConnection DBConnection;
	
	
    private DBConnection()
	{
    	Config config = new Config();    	
    	jdbcUrl = config.getProperty("jdbcUrl");
		userid = config.getProperty("userid");
		password = config.getProperty("password");
		this.connect();
    }
	
	
	public static DBConnection getInstance()
	{
		if(DBConnection==null)
		{
			DBConnection=new DBConnection();
		}
		return DBConnection;
	}	
	

	
	private void connect() {
        try{
        	datasource= new OracleDataSource();
        	datasource.setURL(jdbcUrl);
        } catch (SQLException e) {
        	// Could not connect to the database
        	System.out.println(e.getMessage());
        	
        }        
        
    }
	
	public Connection getConnection() throws SQLException{
       return datasource.getConnection(userid,password);
    }
	
	

}